<script setup>
import BackLink from "@/components/BackLink/index.vue"
import {useRoute, useRouter} from "vue-router";
import {detailsWorkHonorApi, getGraduatedListApi, getStuDetailsApi, getWorkHonorListApi} from "@/api/school.js";
import {formatDate} from "../../../../utils/index.js";
import FilePreView from "@/components/FilePreView/index.vue";
import WangEditor from "@/components/WangEditor/index.vue";
const router = useRouter()
const route = useRoute()

const state = reactive({
  userId: '',
  userInfo:{},
  tableData: [],
  queryParams: {
    pageNum: 1,
    pageSize: 10,
  },
  detailsForm:{

  }
})

const showDia1 = ref(false)

const getUserInfo = async () => {
  const res = await getStuDetailsApi({id:state.userId})
  if(res.code === 200){
    state.userInfo = res.data
  }
}

const getDataList = async () => {
  const res = await getWorkHonorListApi(state.queryParams)
  if (res.code == 200) {
    state.tableData = res.rows
    state.total = res.total
  }
}


onMounted(() => {
  state.userId  = route.query?.id

  // 获取学生信息
  getUserInfo()
  state.queryParams.stuId = state.userId
  getDataList()
})

const handleBack = () => {
  router.go(-1)
}

// 查看详情
const handleDetails = async (item) => {
  const res = await detailsWorkHonorApi({id:item.id})
  if(res.code === 200){
    state.detailsForm = res.data
  }
  showDia1.value = true
}
</script>

<template>
  <div class="outBox">
    <el-card>
      <BackLink/>
      <div class="form-box">
        <div class="form-line">
          <div class="form-item">
            <div class="form-name">姓名</div>
            <div class="form-cont">
              <el-input v-model="state.userInfo.stuName" />
            </div>
          </div>
          <div class="form-item">
            <div class="form-name">学号</div>
            <div class="form-cont">
              <el-input v-model="state.userInfo.stuNum" />
            </div>
          </div>
          <div class="form-item">
            <div class="form-name">班级</div>
            <div class="form-cont">
              <el-input v-model="state.userInfo.stuClass" />
            </div>
          </div>
        </div>
        <div class="form-line">
          <div class="form-item">
            <div class="form-name">院系</div>
            <div class="form-cont">
              <el-input v-model="state.userInfo.stuFaculties" />
            </div>
          </div>
          <div class="form-item">
            <div class="form-name">毕业年份</div>
            <div class="form-cont">
              <el-input v-model="state.userInfo.stuGradYear" />
            </div>
          </div>
          <div class="form-item">
            <div class="form-name">户籍地</div>
            <div class="form-cont">
              <el-input v-model="state.userInfo.stuPlace" />
            </div>
          </div>
        </div>
        <div class="form-textArea">
          <div class="form-item">
            <div class="form-name">在职荣誉</div>
            <div class="text-items">
              <div class="text-item" v-for="item in state.tableData">
                <div class="tit">{{item.honorTitle}}</div>
                <div class="bottom">
                  <div class="time">{{formatDate(item.createTime)}}</div>
                  <div class="link" @click="handleDetails(item)">
                    <el-link type="primary" :underline="false">查看</el-link>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="pageBox">
          <pagination
              v-show="state.total > 0"
              :total="state.total"
              v-model:page="state.queryParams.pageNum"
              v-model:limit="state.queryParams.pageSize"
              @pagination="getDataList"
          />
        </div>
        <div class="center-btns">
          <el-button  @click="handleBack" type="primary">返回</el-button>
        </div>
      </div>
    </el-card>

    <el-dialog v-model="showDia1" title="荣誉详情" width="80%" style="height: 80vh">
      <el-form label-width="80px" ref="classFormRef" :model="state.detailsForm" >
        <el-form-item label="荣誉标题" prop="facultiesId">
          {{state.detailsForm.honorTitle}}
        </el-form-item>

        <el-form-item label="荣誉材料" prop="facultiesId">
          <FilePreView :url="state.detailsForm.honorFile" :file-type="state.detailsForm.honorFileType" width="200px" height="200px" />
        </el-form-item>
        <el-form-item label="荣誉内容" prop="facultiesId">
          <WangEditor v-model="state.detailsForm.honorContent" height="300"/>
        </el-form-item>
      </el-form>
    </el-dialog>

  </div>
</template>

<style scoped lang="scss">
.text-items{
  padding: 20px;
  display: grid;
  justify-content: space-between;
  grid-template-columns: repeat(2, 550px);
  .text-item{
    margin-bottom: 20px;
  }
  .tit{
    font-size: 22px;
    margin-bottom: 5px;
  }
  .bottom{
    display: flex;
    justify-content: space-between;
    .time{
      color: #827e7d;
    }
  }
}
.center-btns{
  display: flex;
  justify-content: center;
  margin-top: 20px;
}
.form-textArea{
  border: 1px solid #e5e5e5;
  min-height:400px;
  :deep(.el-textarea){
    --el-input-border-color:#fff !important;
    --el-input-focus-border:#fff !important;
    --el-input-hover-border-color:#fff !important;
    --el-input-focus-border-color:#fff !important;

  }
}
.form-box{
  .form-name{
    background: #f1f7ff;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100px;
    font-weight: bold;
    border-right: 1px solid #e5e5e5;
  }
  .form-line{
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    border: 1px solid #e5e5e5;
    margin-bottom: 20px;
    .form-item{
      display: flex;
      align-items: center;

      .form-cont{
        width: calc(100% - 100px);
        :deep(.el-input){
          --el-input-border-color:#fff !important;
          --el-input-focus-border:#fff !important;
          --el-input-focus-border-color:#fff !important;
        }
      }
    }
  }
}
</style>
